package com.dlb.andorid.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.dlb.andorid.App;
import com.dlb.andorid.R;
import com.dlb.andorid.activity.AboutActivity;
import com.dlb.andorid.activity.AccountActivity;
import com.dlb.andorid.activity.AddressListActivity;
import com.dlb.andorid.activity.CouponListActivity;
import com.dlb.andorid.activity.LoginActivity;
import com.dlb.andorid.activity.MxActivity;
import com.dlb.andorid.activity.MyCollectActivity;
import com.dlb.andorid.activity.MyLyActivity;
import com.dlb.andorid.activity.MyPropertyActivity;
import com.dlb.andorid.activity.OrderActivity;
import com.dlb.andorid.activity.PointActivity;
import com.dlb.andorid.activity.RechargeActivity;
import com.dlb.andorid.activity.SHRZActivity;
import com.dlb.andorid.activity.TGZQActivity;
import com.dlb.andorid.activity.TxActivity;
import com.dlb.andorid.activity.WebActivity;
import com.kwan.xframe.mvp.view.activity.BaseWebActivity;
import com.kwan.xframe.mvp.view.fragment.BasePageItemFragment;
import com.kwan.xframe.util.SPUtil;


public class MineFragment extends BasePageItemFragment {

	public static MineFragment newInstance() {
		MineFragment fragment = new MineFragment();
		Bundle args = new Bundle();
		fragment.setArguments(args);
		return fragment;
	}

	@Override
	protected String getItemTag() {
		return "Home";
	}


	private View tv_all_order, ll_address, ll_my_property, ll_my_collect, ll_logout, ll_gywm, ll_zhgl, ll_yhq,
			ll_zxcz, ll_tx, ll_jf, ll_mx, ll_wdpj, ll_tgzq, ll_wdly, ll_shrz, ll_psyrz;

	View ll_dpj, ll_ywc, ll_shtk, ll_dsh, ll_dzf;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		tv_all_order = mContentView.findViewById(R.id.tv_all_order);
		ll_address = mContentView.findViewById(R.id.ll_address);
		ll_my_property = mContentView.findViewById(R.id.ll_my_property);
		ll_my_collect = mContentView.findViewById(R.id.ll_my_collect);
		ll_gywm = mContentView.findViewById(R.id.ll_gywm);
		ll_zhgl = mContentView.findViewById(R.id.ll_zhgl);
		ll_logout = mContentView.findViewById(R.id.ll_logout);
		ll_yhq = mContentView.findViewById(R.id.ll_yhq);
		ll_tx = mContentView.findViewById(R.id.ll_tx);
		ll_zxcz = mContentView.findViewById(R.id.ll_zxcz);
		ll_jf = mContentView.findViewById(R.id.ll_jf);
		ll_mx = mContentView.findViewById(R.id.ll_mx);
		ll_wdpj = mContentView.findViewById(R.id.ll_wdpj);
		ll_tgzq = mContentView.findViewById(R.id.ll_tgzq);
		ll_wdly = mContentView.findViewById(R.id.ll_wdly);
		ll_shrz = mContentView.findViewById(R.id.ll_shrz);
		ll_psyrz = mContentView.findViewById(R.id.ll_psyrz);

		ll_dpj = mContentView.findViewById(R.id.ll_dpj);
		ll_ywc = mContentView.findViewById(R.id.ll_ywc);
		ll_shtk = mContentView.findViewById(R.id.ll_shtk);
		ll_dsh = mContentView.findViewById(R.id.ll_dsh);
		ll_dzf = mContentView.findViewById(R.id.ll_dzf);


		ll_dpj.setOnClickListener(this);
		ll_ywc.setOnClickListener(this);
		ll_shtk.setOnClickListener(this);
		ll_dsh.setOnClickListener(this);
		ll_dzf.setOnClickListener(this);


		ll_my_collect.setOnClickListener(this);
		tv_all_order.setOnClickListener(this);
		ll_address.setOnClickListener(this);
		ll_my_property.setOnClickListener(this);
		ll_logout.setOnClickListener(this);
		ll_gywm.setOnClickListener(this);
		ll_zhgl.setOnClickListener(this);
		ll_yhq.setOnClickListener(this);
		ll_tx.setOnClickListener(this);
		ll_zxcz.setOnClickListener(this);
		ll_jf.setOnClickListener(this);
		ll_mx.setOnClickListener(this);
		ll_wdpj.setOnClickListener(this);
		ll_tgzq.setOnClickListener(this);
		ll_wdly.setOnClickListener(this);
		ll_shrz.setOnClickListener(this);
		ll_psyrz.setOnClickListener(this);

		if (App.mUserInfo != null) {

			((TextView) mContentView.findViewById(R.id.tv_name)).setText(App.mUserInfo.getNickname());
			String str = App.mUserInfo.getPhone();

			if (str == null)
				str = "";

			if (str.length() == 11) {
				String p = str.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
				((TextView) mContentView.findViewById(R.id.tv_phone)).setText(p);
			} else {
				((TextView) mContentView.findViewById(R.id.tv_phone)).setText(str);
			}
		}
	}

	@Override
	public void onResume() {
		super.onResume();
	}


	@Override
	public void onClick(View v) {
		super.onClick(v);
		if (v == tv_all_order) {
			go2Activity(OrderActivity.class, null, false);
		} else if (v == ll_address) {
			go2Activity(AddressListActivity.class, null, false);
		} else if (v == ll_my_property) {
			go2Activity(MyPropertyActivity.class, null, false);
		} else if (v == ll_my_collect) {
//			Bundle bundle = new Bundle();
//			bundle.putString("url", "http://www.dilinbang.com/collection.php?user_id=" + App.mUserInfo.getUser_id());
//			bundle.putString("title", "我的收藏");
//			bundle.putInt("mode", BaseWebActivity.MODE_WEB);
//			go2Activity(WebActivity.class, bundle, false);
			go2Activity(MyCollectActivity.class, null, false);
		} else if (v == ll_logout) {
			SPUtil.setUserPwd("");
			SPUtil.setUserAccount("");
			SPUtil.setLoginType(-1);
			go2Activity(LoginActivity.class, null, true);
		} else if (v == ll_gywm) {
			go2Activity(AboutActivity.class, null, false);
		} else if (v == ll_zhgl) {
			go2Activity(AccountActivity.class, null, false);
		} else if (v == ll_yhq) {
			go2Activity(CouponListActivity.class, null, false);
		} else if (v == ll_tx) {
			go2Activity(TxActivity.class, null, false);
		} else if (v == ll_zxcz) {
			go2Activity(RechargeActivity.class, null, false);
		} else if (v == ll_jf) {
			go2Activity(PointActivity.class, null, false);
		} else if (v == ll_mx) {
			go2Activity(MxActivity.class, null, false);
		} else if (v == ll_wdpj) {

			Bundle bundle = new Bundle();
			bundle.putString("url", "http://www.dilinbang.com/evaluate.php?user_id=" + App.mUserInfo.getUser_id());
			bundle.putString("title", "我的评价");
			bundle.putInt("mode", BaseWebActivity.MODE_WEB);
			go2Activity(WebActivity.class, bundle, false);

			//go2Activity(MyCommentActivity.class, null, false);
		} else if (v == ll_tgzq) {
			go2Activity(TGZQActivity.class, null, false);
		} else if (v == ll_wdly) {
			go2Activity(MyLyActivity.class, null, false);
		} else if (v == ll_shrz) {
			Bundle bundle = new Bundle();
			bundle.putInt("type", SHRZActivity.REG_TYPE_MERCHANT);
			go2Activity(SHRZActivity.class, bundle, false);
		} else if (v == ll_psyrz) {
			Bundle bundle = new Bundle();
			bundle.putInt("type", SHRZActivity.REG_TYPE_RIDER);
			go2Activity(SHRZActivity.class, bundle, false);
		} else if (v == ll_dzf) {

			Bundle bundle = new Bundle();
			bundle.putInt("index", 1);
			go2Activity(OrderActivity.class, bundle, false);
		}
		else if (v == ll_dsh) {

			Bundle bundle = new Bundle();
			bundle.putInt("index", 2);
			go2Activity(OrderActivity.class, bundle, false);
		}
		else if (v == ll_shtk) {

			Bundle bundle = new Bundle();
			bundle.putInt("index", 4);
			go2Activity(OrderActivity.class, bundle, false);
		}
		else if (v == ll_ywc) {

			Bundle bundle = new Bundle();
			bundle.putInt("index", 5);
			go2Activity(OrderActivity.class, bundle, false);
		}
		else if (v == ll_dpj) {

			Bundle bundle = new Bundle();
			bundle.putInt("index", 3);
			go2Activity(OrderActivity.class, bundle, false);
		}
	}


	@Override
	public void onPause() {
		super.onPause();
	}

	@Override
	public void onStop() {
		super.onStop();
	}


	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	@Override
	protected int getContentViewId() {
		return R.layout.fragment_mine;
	}

	//第一次获取数据
	@Override
	public void fetchData() {

	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
	}

	@Override
	public String getPageName() {
		return null;
	}
}
